package com.haois.mp.database.module.offaccounts.rest;

import com.haois.mp.database.exception.ErrorException;
import me.chanjar.weixin.common.exception.WxErrorException;
import com.haois.mp.database.module.basic.controller.BaseController;
import com.haois.mp.database.module.remote.service.IYellowService;
import com.haois.mp.database.util.mp.ProduceJwt;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * Created by RuiHaoZ on 2017/12/5.
 */
@RestController
@RequestMapping("/wxmp/rest/yellow")
public class YellowRestController extends BaseController {

    private static final Logger logger = LoggerFactory
            .getLogger(YellowRestController.class);

    @Autowired
    private IYellowService iYellowService;
    private ProduceJwt produceJwt = new ProduceJwt();

    @RequestMapping(value = "/getFollow", method = RequestMethod.GET)
    public Map getFollow(String oid, HttpServletRequest request) throws
            RuntimeException, WxErrorException, ErrorException {
        String access_token = (String) request.getAttribute("access_token");
        Map map = iYellowService.getFollow(access_token,getPagerParams(request));
        return map;
    }

    @RequestMapping(value = "/getAllOrg", method = RequestMethod.GET)
    public Map getOrganizeList(HttpServletRequest request) throws
            RuntimeException, WxErrorException, ErrorException {
        String access_token = produceJwt.getShareToken();
        Map map = iYellowService.getAllOrg(access_token,getPagerParams(request));
        return map;
    }


    @RequestMapping(value = "/exitGroup", method = RequestMethod.POST)
    public Map exit(String oid, HttpServletRequest request) throws
            RuntimeException, WxErrorException, ErrorException {
        String access_token = (String) request.getAttribute("access_token");
        Map map = iYellowService.unFollowGroup(oid, access_token);
        return map;
    }

}
